// custom-tab-bar/index.js
// const { tabBar } = require("../utils/tab-service")
// const { tabBar } from "../utils/tab-service.js"
const App = getApp();

Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  options: {
    styleIsolation: 'shared',
  },

  /**
   * 组件的初始数据
   */
  data: {
    // list: tabBar.list
    // active: "work",
    // list: [{
    //   "pagePath": "/pages/tabbar/work/index",
    //   "text": "工作",
    //   "name": "work",
    //   "iconPath": "/images/tabbar/work.png",
    //   "selectedIconPath": "/images/tabbar/work-active.png"
    // },
    // {
    //   "pagePath": "/pages/tabbar/my/index",
    //   "text": "我的",
    //   "name": "my",
    //   "iconPath": "/images/tabbar/my.png",
    //   "selectedIconPath": "/images/tabbar/my-active.png"
    // }]
  },

  lifetimes: {
    ready() {

    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项
      const token = wx.getStorageSync('token')
      if (!token) {
        // 没有token，去登录
        wx.navigateTo({
          url: '/pages/login/index',
        })
        return;
      }
      this.setData({ active: event.detail });
      App.globalData.activeTab = event.detail;
      const url = this.data.list.find((item) => item.name === event.detail).pagePath;
      // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      //   this.getTabBar().setData({
      //     list: this.data.list
      //   })
      // }
      wx.switchTab({
        url: url,
      })
    },
  }
})